var app = getApp();
var c = require('../common.js');
// pages/myzizhi/myzizhi.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    array: ['个人', '单位'],
    index: 0,
    multiArray: [
      [],
      []
    ],
    multiIndex: [0, 0]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this;
    var upone = "multiArray[" + 0 + "]";
    var uptwo = "multiArray[" + 1 + "]";
    wx.request({
      url: app.url+'cateinfo',
      data: {},
      header: {
        'content-type': 'application/json'
      },
      success: function(res) {
        console.log(res);
        console.log(res.data);
        that.setData({
          [upone]: res.data.one,
          [uptwo]: res.data.two[0],
          twoinfo: res.data.two,
          twoinfo_id:res.data.two_id
        })
        console.log(that.data.multiArray);
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  bindPickerChange: function(e) {
    console.log('picker发送选择改变11，携带值为', e.detail.value)
    this.setData({
      index: e.detail.value
    })
  },
  bindMultiPickerChange: function(e) {
    console.log(e);
    console.log('picker发送选择改变22，携带值为', e.detail.value)
    this.setData({
      multiIndex: e.detail.value
    })
  },
  bindMultiPickerColumnChange: function(e) {
    console.log('修改的列为', e.detail.column, '，值为', e.detail.value);
    if (e.detail.column==0){
      var twoinfo = this.data.twoinfo;
      var column = e.detail.column;
      var twovalue = twoinfo[e.detail.value];
      var upone = "multiArray[" + 1 + "]";
      this.setData({
        [upone]: twovalue
      })
      console.log(this.data);
    }
  },
  formSubmit:function(e){
    var user_id=wx.getStorageSync('userInfo').user_id;
    var twoinfo_id = this.data.twoinfo_id;
    var cate=e.detail.value.cate;
    var cate = e.detail.value.cate;
    //email
    var email = e.detail.value.email;
    //身份证
    var idcord = e.detail.value.idcord;
    //姓名
    var name = e.detail.value.name;
    //手机
    var phone = e.detail.value.phone;
    //身份
    var shenf = e.detail.value.shenf;
    //获取课程分类id
    var twoinfo_id=twoinfo_id[cate[0]][cate[1]];

    if (email==''){
        wx.showToast({
          title: '请填写邮箱地址',
          icon: 'none',
        })
        return;
    }
    if (idcord == '') {
      wx.showToast({
        title: '请填写身份证号码',
        icon: 'none',
      })
      return;
    }
    if (name == '') {
      wx.showToast({
        title: '请填写姓名',
        icon: 'none',
      })
      return;
    }
    if (phone == '') {
      wx.showToast({
        title: '请填写手机号',
        icon: 'none',
      })
      return;
    }
      // { name: name, idcord: idcord, phone: phone, email: email, shenf: shenf, twoinfo_id: twoinfo_id, user_id: user_id},
    var url='?name=' + name + '&idcord=' + idcord + '&phone=' + phone + '&email=' + email + '&twoinfo_id=' + twoinfo_id + ' &user_id=' + user_id;
            if (shenf==0){
                wx.navigateTo({
                  // url: '/pages/myzizhistudent/myzizhistudent' + url,
                  url: '/pages/myzizhiteacher/myzizhiteacher' + url,
                })
            } else if (shenf == 1){
              wx.navigateTo({
                // url: '/pages/myzizhiteacher/myzizhiteacher' + url,
                url: '/pages/myzizhijigou/myzizhijigou' + url,
              })
            } else if (shenf == 2) {
              wx.navigateTo({
                url: '/pages/myzizhijingying/myzizhijingying' + url,
              })
            }else if (shenf == 3) {
              wx.navigateTo({
                url: '/pages/myzizhijigou/myzizhijigou' + url,
              })
            }
          
    

  }
})